// 新建 view

const path = require("path")
const fs = require("fs");

// assets 目录
const assetsDir = path.join(path.dirname(__dirname), "assets")
const gameDir = path.join(assetsDir, "script", "game")
// 模块名
const mod = process.argv[2]
const viewName = process.argv[3]
// 说明
const comment = process.argv[4] || ''
if (!mod || !viewName || !comment) {
    console.error("使用方法, tools 目录下运行: node newView 游戏模块 view组件名 注释")
    process.exit(1)
}

// 首字母大写
const clsName = viewName.charAt(0).toUpperCase() + viewName.slice(1) + "View"

const text = `import { _decorator, Component, Node } from 'cc';

const { ccclass, property } = _decorator;

// ${comment}
@ccclass('${clsName}')
export class ${clsName} extends Component {
    // @property({
    //     type: Node,
    //     tooltip: "说明"
    // })
    // demo: Node

    // start() {
    //
    // }

    // onLoad() {
    //
    // }
}
`

fs.writeFileSync(path.join(gameDir, mod, "view", viewName + "View.ts"), text)